#ifndef _FSTAPP_DEBUG_H
#define _FSTAPP_DEBUG_H
#include <stdio.h>
#include <stdlib.h>

// #include "FreeRTOSTrace.h"
// #include "globle_include.h"

/*
* 通过下面的宏控制相应模块输出log
* 如果不采用下方定义的log_xxx打印接口，请在输出信息开头处包含简写的模块名称
* 例：LOG_DB("[aplay] hello test \n")
*/
#define ENABLE_LOG_APLAY	0
#define ENABLE_LOG_AREC		0
#define ENABLE_LOG_VIDEO	0
#define ENABLE_LOG_GUI		0
#define ENABLE_LOG_RX_RECV_TASK   0   // rx_recv_task  log_debug
#define ENABLE_LOG_OS_NVRAM	0   
#define ENABLE_LOG_NVRAM	0 
#define ENABLE_LOG_RF_API	0	// rf drv ioctl
#define ENABLE_LOG_RF_DEV	0
#define ENABLE_LOG_MED		0
#define ENABLE_LOG_MMITASK		0
#define ENABLE_LOG_KEY		0
#define ENABLE_LOG_GPIO		0
#define ENABLE_LOG_MAIN		1
#define ENABLE_LOG_ENCRYPT	0
#define ENABLE_LOG_LCD		1
#define ENABLE_LOG_VPLY_APP	1


/* define mode name for dbg */
#define MNAME_APLAY     	"APLAY"
#define MNAME_AREC     		"AREC"
#define MNAME_VIDEO     	"VIDEO"
#define MNAME_GUI	    	"GUI"
#define MNAME_RX_RECV_TASK  "RRTSK"
#define MNAME_OS_NVRAM  	"OSNV"
#define MNAME_NVRAM  		"NV"
#define MNAME_RF_API		"RFAPI"
#define MNAME_RF_DRV_PARAM	"RFPARAM"
#define MNAME_RF_DEV		"RF-DEV"
#define MNAME_MED			"MED"
#define MNAME_MMITASK		"MMITSK"
#define MNAME_KEY			"KEY"
#define MNAME_GPIO			"GPIO"
#define MNAME_MAIN			"MAIN"
#define MNAME_ENCRYPT		"ENC"
#define MNAME_LCD			"LCD"
#define MNAME_VPLY_APP		"VPLY_APP"

#define LOG_DB   printf    //sysprintf
#ifdef __IC_AK37E__
#define USE_AK_PRINT_API

#endif
#define PRINT_FUN_NAME  LOG_DB("\n%s\n",__func__);
//#define PRINT_FUN_NAME
#define ENTER_FUN  LOG_DB("\n%s in\n",__func__);
#define LEVEA_FUN  LOG_DB("\n%s out\n",__func__);

#define DEBUG_LEVEL 3 // 2
#define LOG_TAG //should be a c string like "hello"
/*
* log_error：提示所有错误信息，强制替换各模块里的出错log
* 其它可选择使用
*/
#if !defined(__PC_SIM__)

#if (DEBUG_LEVEL>=1)																																			

#ifdef USE_AK_PRINT_API
										
#define log_error(format, arg...)	do { ak_print(MODULE_ID_APP, LOG_LEVEL_ERROR, LOG_TAG"[%d:%s] "format"\n",__LINE__, __func__, ##arg);}\
									while (0)
#else
#define log_error(format, arg...)	do { LOG_DB(LOG_TAG "[ERROR]%d,%s--- "format"\n",\
										__LINE__,__func__, ## arg);} \
									while (0)
#endif
#else								
#define log_error(format, arg...)	
#endif

/* warn */
#if (DEBUG_LEVEL>=2)	

#ifdef USE_AK_PRINT_API
																				
#define log_warn(format, arg...)	do { ak_print(MODULE_ID_APP, LOG_LEVEL_WARNING, LOG_TAG"[%d:%s] "format"\n",__LINE__, __func__, ##arg);}\
									while (0)															
#else

#define log_warn(format, arg...)	do { LOG_DB(LOG_TAG "[WARN]%d,%s--- "format"\n",\
										__LINE__,__func__, ## arg);} \
									while (0)
#endif
#else				
#define log_warn(format, arg...)												
#endif

#if (DEBUG_LEVEL>=3)	

#ifdef USE_AK_PRINT_API
#define log_debug(format, arg...)	do { ak_print(MODULE_ID_APP, LOG_LEVEL_NORMAL, LOG_TAG"[%d:%s] "format"\n",__LINE__, __func__, ##arg);}\
									while (0)

#define log_print(format, arg...)	do { ak_print(MODULE_ID_APP, LOG_LEVEL_NORMAL, LOG_TAG format"\n", ##arg);}\
																			while (0)

#else
#define log_debug(format, arg...)	do { LOG_DB(LOG_TAG "[DBG]%d,%s--- "format"\n",\
										__LINE__,__func__, ## arg);} \
									while (0)
										
#define log_print(format, arg...)	do { LOG_DB(LOG_TAG format"\n",\
										## arg);} \
									while (0)
#endif
#else				
#define log_debug(format, arg...)
#define log_print(format, arg...)

#endif
#else
#if (DEBUG_LEVEL>=1)																																			

#ifdef USE_AK_PRINT_API

#define log_error(format, ...)	do { ak_print(MODULE_ID_APP, LOG_LEVEL_ERROR, LOG_TAG"[%d:%s] "format"\n",__LINE__, __func__, ##arg);}\
									while (0)
#else
#define log_error(format, ...)	      do { LOG_DB(LOG_TAG "[ERROR]%d,%s--- " format "\n",\
										__LINE__,__func__, ##__VA_ARGS__);} \
									while (0)
#endif
#else								
#define log_error(format, ...)	
#endif

/* warn */
#if (DEBUG_LEVEL>=2)	

#ifdef USE_AK_PRINT_API

#define log_warn(format, ...)	do { ak_print(MODULE_ID_APP, LOG_LEVEL_WARNING, LOG_TAG"[%d:%s] "format"\n",__LINE__, __func__, ##arg);}\
									while (0)															
#else

#define log_warn(format, ...)	do { LOG_DB(LOG_TAG "[WARN]%d,%s--- "format"\n",\
										__LINE__,__func__, ##__VA_ARGS__);} \
									while (0)
#endif
#else				
#define log_warn(format, ...)												
#endif

#if (DEBUG_LEVEL>=3)	

#ifdef USE_AK_PRINT_API
#define log_debug(format, ...)	do { ak_print(MODULE_ID_APP, LOG_LEVEL_NORMAL, LOG_TAG"[%d:%s] "format"\n",__LINE__, __func__, ##arg);}\
									while (0)

#define log_print(format, ...)	do { ak_print(MODULE_ID_APP, LOG_LEVEL_NORMAL, LOG_TAG format"\n", ##arg);}\
																			while (0)

#else
#define log_debug(format, ...)	do { LOG_DB(LOG_TAG "[DBG]%d,%s--- "format"\n",\
										__LINE__,__func__, ##__VA_ARGS__);} \
									while (0)

#define log_print(format, ...)	do { LOG_DB(LOG_TAG format"\n",\
										##__VA_ARGS__);} \
									while (0)
#endif
#else				
#define log_debug(format, ...)
#define log_print(format, ...)

#endif
#endif
//#if (DEBUG_LEVEL==0)
//#define log_print(format, arg...)
//#define log_debug(format, arg...)												
//#define log_warn(format, arg...)												
//#define log_error(format, arg...)	
//#elif (DEBUG_LEVEL==1)
//#define log_print(format, arg...)
//#define log_debug(format, arg...)												
//#define log_warn(format, arg...)												
//													
//#define log_error(format, arg...)	do { LOG_DB(LOG_TAG "[ERROR]%d,%s--- "format"\n",\
//										__LINE__,__func__, ## arg);} \
//									while (0)
//
//#elif (DEBUG_LEVEL==2)
//
//#define log_print(format, arg...)
//#define log_debug(format, arg...)												
//#define log_warn(format, arg...)	do { LOG_DB(LOG_TAG "[WARN]%d,%s--- "format"\n",\
//												__LINE__,__func__, ## arg);} \
//									while (0)
//												
//#define log_error(format, arg...)	do { LOG_DB(LOG_TAG "[ERROR]%d,%s--- "format"\n",\
//										__LINE__,__func__, ## arg);} \
//									while (0)
//
//#elif (DEBUG_LEVEL==3)
//
//#define log_print(format, arg...)	do { LOG_DB(LOG_TAG format"\n",\
//												 ## arg);} \
//									while (0)
//
//#define log_debug(format, arg...)	do { LOG_DB(LOG_TAG "[DBG]%d,%s--- "format"\n",\
//												__LINE__,__func__, ## arg);} \
//									while (0)
//
//#define log_warn(format, arg...)	do { LOG_DB(LOG_TAG "[WARN]%d,%s--- "format"\n",\
//												__LINE__,__func__, ## arg);} \
//									while (0)
//																								
//#define log_error(format, arg...)	do { LOG_DB(LOG_TAG "[ERROR]%d,%s--- "format"\n",\
//										__LINE__,__func__, ## arg);} \
//									while (0)
//
//#endif

#endif


